import Vue from 'vue'
import VueRouter from 'vue-router'
import Position from '../view/Pisition/Worklist'
// import News from '../view/News'
const News = () => import('../view/News')
// import Company from '../view/Company'
const Company = () => import('../view/Company')

// import Myhome from '../view/Myhome'
const Myhome = () => import('../view/Myhome')

// import Worklist from '../view/Pisition/Worklist'
const Worklist = () => import('../view/Pisition/Worklist')

// import Workinfo from '../view/Pisition/Workinfo'
const Workinfo = () => import('../view/Pisition/Workinfo')

// import Interaction from '../view/News/Interaction'
const Interaction = () => import('../view/News/Interaction')

// import Login from '../view/Login'
const Login = () => import('../view/Login')

// import ChangePassword from '../view/ChangePassword'
const ChangePassword = () => import('../view/ChangePassword')

// import Login1 from '../components/Login/card'
const Login1 = () => import('../components/Login/card')

// import Register from '../components/Login/phone'
const Register = () => import('../components/Login/phone')

// import Companyinfo from '../view/Company/Companyinfo'
const Companyinfo = () => import('../view/Company/Companyinfo')

// import PInfo from '../view/Myhome/PInfo'
const PInfo = () => import('../view/Myhome/PInfo')

/*  */

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/position/worklist'
  },
  {
    path: '/position/worklist',
    component: Position
  },
  {
    path: '/position/worklist',
    component: Worklist
  },
  {
    path: '/new',
    component: News
  },
  {
    path: '/company',
    component: Company
  },
  {
    path: '/myhome',
    component: Myhome

  },
  {
    path: '/position/workinfo/:id',
    component: Workinfo
  },
  {
    path: '/login',
    component: Login,
    children: [
      {
        path: '/register',
        component: Register
      },
      {
        path: '/login',
        component: Login1
      }
    ]
  },
  {
    name: '/changepassword',
    path: '/changepassword/:utel',
    component: ChangePassword

  },
  {
    path: '/company/companyinfo/:id',
    component: Companyinfo

  },
  {
    path: '/myhome/myinfo',
    component: PInfo
  },
  {
    path: '/news/interaction',
    component: Interaction
  }

  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  console.log(to.path)

  if (to.path === '/login' || to.path === '/register' || to.path === '/position/worklist' ||
   to.path === '/company' || to.path === '/new' || to.path === '/myhome' || to.name === '/changepassword') return next()
  if (to.name === '/changepassword') {
    return next('/changepassword/:utel')
  } else if (!localStorage.getItem('user')) {
    return next('/login')
  }
  next()
})
export default router
